import socket
import json
import binascii

HOST = '127.0.0.1'
PORT = 65432

# 打开图像文件并读取二进制数据
with open('1.png', 'rb') as f:
    image_data_binary = f.read()

# 将图像数据转换为十六进制字符串
image_data_hex = binascii.hexlify(image_data_binary).decode('utf-8')

# 构造JSON数据
student = {
    'name': 'John',
    'id': 123,
    'image': image_data_hex,
}
json_data = json.dumps(student).encode('utf-8')

# 发送JSON数据到服务器
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall(json_data)
    print('Sent data to server:', student)